<template>
    <d2-container type="card">
        <header>
            <el-form :inline="true" :model="selectFrom" class="demo-form-inline" size="mini">
                <el-form-item label="客户名称">
                    <el-input v-model="selectFrom.name" placeholder="客户名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="getUserInfoData()">查询</el-button>
                </el-form-item>
            </el-form>
        </header>
        <footer>
            <el-table :data="tableData" border style="width: 100%" size="mini" :height="height">
                <el-table-column prop="image" label="头像" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.image">
                            <el-image style="width: 100px; height: 100px" :src="scope.row.imageUrlList[0]"
                                :preview-src-list="[scope.row.imageUrlList[0]]">
                            </el-image>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="id" label="客户ID" align="center">
                </el-table-column>
                <el-table-column prop="name" label="名称" align="center">
                </el-table-column>
                <el-table-column prop="phone" label="手机号" align="center">
                </el-table-column>
                <el-table-column prop="consumptionPrice" label="消费费用" align="center">
                </el-table-column>
                <el-table-column label="推荐用户" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.recommendUserInfo">{{ scope.row.recommendUserInfo.name }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="integral" label="积分" align="center">
                </el-table-column>
                <el-table-column prop="savingsPrice" label="储蓄累计节省" align="center">
                </el-table-column>
                <el-table-column prop="isRebate" label="是否返利" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.isRebate == 0">否</div>
                        <div v-if="scope.row.isRebate == 1">是</div>
                    </template>
                </el-table-column>
                <el-table-column prop="distributionPrice" label="分销金额" align="center">
                </el-table-column>
                <el-table-column prop="isDistribution" label="是否是分销商" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.isDistribution == 0">普通分销商</div>
                        <div v-if="scope.row.isDistribution == 1">专业分销商</div>
                        <div v-if="scope.row.isDistribution == 2">不是</div>
                    </template>
                </el-table-column>
                <el-table-column prop="distributionGrade" label="分销商等级" align="center">
                </el-table-column>
                <el-table-column prop="balance" label="余额" align="center">
                </el-table-column>
                <el-table-column prop="withdrawalTotal" label="提现总额" align="center">
                </el-table-column>
                <el-table-column prop="invitationNum" label="邀请人数" align="center">
                </el-table-column>
                <el-table-column prop="invitationSaveNum" label="邀请储蓄会员人数" align="center">
                </el-table-column>
                <el-table-column prop="state" label="状态" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.state == 0">冻结</div>
                        <div v-if="scope.row.state == 1">存在</div>
                    </template>
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间" align="center">
                </el-table-column>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" v-if="scope.row.state == 0"
                            @click="thawUserInfoData(scope.row)">解冻</el-button>
                        <el-button type="danger" size="mini" v-if="scope.row.state == 1"
                            @click="freezeUserInfoData(scope.row)">冻结</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="block" style="text-align:center">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                    :page-sizes="[5, 10, 15, 20]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>
        </footer>
    </d2-container>
</template>
  
<script>
import { getUserInfo, freezeUserInfo, thawUserInfo } from "@/api/modules/user_info.js"
export default {
    name: 'shopInfo',
    data() {
        return {
            selectFrom: {},//搜索栏
            tableData: [],//表格数据
            page: 1,
            limit: 10,
            total: 0,
            height: window.innerHeight - 250, //表格高度
        }
    },
    mounted() {
        this.getUserInfoData();
        //-------------------------表格响应----------------//
        this.createHeight();
        //当页面发生变化时，表格高度固定
        window.onresize = () => {
            return (() => {
                this.$nextTick(() => {
                    this.createHeight();
                });
            })();
        };
    },
    methods: {
        //解冻客户
        thawUserInfoData(row) {
            thawUserInfo(row).then(res => {
                this.getUserInfoData();
            })
        },
        //冻结客户
        freezeUserInfoData(row) {
            freezeUserInfo(row).then(res => {
                this.getUserInfoData();
            })
        },
        //获取客户数据
        getUserInfoData() {
            this.selectFrom.page = this.page;
            this.selectFrom.limit = this.limit;
            getUserInfo(this.selectFrom).then(res => {
                this.tableData = res.dataList;
                this.total = res.total;
            })
        },
        handleSizeChange(val) {
            this.limit = val;
            this.getUserInfoData();
        },
        handleCurrentChange(val) {
            this.page = val;
            this.getUserInfoData();
        },
        //---------------自动变更表格高度------------------//
        createHeight() {
            this.height = window.innerHeight - 250;
        }
    }
}
</script>
  